package com.core.page;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 分页相关,不再使用pagebean
 * 
 * @author pt-chenqw
 *
 * @param <T>
 */
public class PagerResult<T> implements Serializable {

	private static final long serialVersionUID = 1L;
	
	/**结果列表*/
	private List<T> results;
	
	/**分页器*/
	private Pager pager;
	
	private T pagerNum;
	
	private T allSum;
	
	public PagerResult(){}

	public PagerResult(List<T> results, Pager pager) {
		super();
		this.results = results;
		this.pager = pager;
	}

	public List<T> getResults() {
		return results;
	}

	public void setResults(List<T> results) {
		this.results = results;
	}
	
	public void setResult(List<?> resultList,Class<? extends T> cls) {
		this.results = new ArrayList<>();
		if(resultList == null){
			return;
		}
		for (Object object : resultList) {
			results.add(cls.cast(object));
		}
	}
	
	public void setResult(Iterator<?> resultList,Class<? extends T> cls) {
		this.results = new ArrayList<>();
		if(resultList == null){
			return;
		}
		while(resultList.hasNext()){
			results.add(cls.cast(resultList.next()));
		}
	}

	public Pager getPager() {
		return pager;
	}

	public void setPager(Pager pager) {
		this.pager = pager;
	}

	public T getPagerNum() {
		return pagerNum;
	}

	public void setPagerNum(T pagerNum) {
		this.pagerNum = pagerNum;
	}

	public T getAllSum() {
		return allSum;
	}

	public void setAllSum(T allSum) {
		this.allSum = allSum;
	}
	
	/**
	 * 设置结果列表和分页器
	 * @param result
	 * @param pager
	 */
	public void create(List<T> results,Pager pager){
		this.results = results;
		this.pager = pager;
	}
	
	public void create(List<T> resultList,Pager pager,Class<T> cls){
		setResult(resultList, cls);
		this.pager = pager;
	}
	
}
